package com.itheima.test3;

import java.util.ArrayList;
import java.util.Collections;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Test {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //设置奖池
        ArrayList<Integer> list = new ArrayList<>();
        Collections.addAll(list, 50, 20, 30, 500, 400, 800, 900);

        //创建运行时的对象
        MyCallable m1 = new MyCallable(list);

        //创建返回结果的对象
        FutureTask<Integer> ft1 = new FutureTask<>(m1);
        FutureTask<Integer> ft2 = new FutureTask<>(m1);

        //创建线程对象
        Thread t1 = new Thread(ft1);
        Thread t2 = new Thread(ft2);
        //设置名字
        t1.setName("抽奖箱1");
        t2.setName("抽奖箱2");
        //开启线程
        t1.start();
        t2.start();

        Integer max1 = ft1.get();
        Integer max2 = ft2.get();
        //System.out.println(max1);
        //System.out.println(max2);
        if(max1 > max2){
            System.out.println("最大值在抽奖箱1  " + max1);
        }else{
            System.out.println("最大值在抽奖箱2  " + max2);
        }
    }
}
